Main
✎🔗Main:
if __name__ == '__main__':
# Initialize the node with rospy
rospy.init_node('talker', anonymous=False)
# Create the NodeName object
node = Talker()
# Setup proper shutdown behavior
rospy.on_shutdown(node.on_shutdown)
# Keep it spinning to keep the node alive
rospy.spin()
rospy.init_node('talker', anonymous=False) initialize a node named talker. Note that this name can be overwritten by a launch file. The launch file can also push this node down namespaces. If the anonymous argument is set to True then a random string of numbers will be append to the name of the node. Usually we don’t use anonymous nodes.
node = Talker() creates an instance of the Talker object. More details in the next section.
rospy.on_shutdown(node.on_shutdown) ensures that the node.on_shutdown will be called when the node is shutdown.
rospy.spin() blocks to keep the script alive. This makes sure the node stays alive and all the publication/subscriptions work correctly.





